import { Route, Redirect } from 'react-router-dom'
import { useAuth } from '../context/AuthProvider'

const AuthRoute = ({ authCheckType,children, ...rest }) => {
    const { user } = useAuth();
    console.log(user)
    if (authCheckType === "authed" && !Object.keys(user).length) {
        return <Redirect to="/login" />;
    }

    if (authCheckType === "unauthed" && !!Object.keys(user).length) {
        return <Redirect to="/" />;
    }

    return <Route {...rest}>
        {children}
    </Route>;
};

export default AuthRoute;